package net.csdn.business.mirror.scheduled;

import lombok.extern.slf4j.Slf4j;
import net.csdn.business.mirror.service.ImportMirrorService;
import net.csdn.business.mirror.service.UserGithubTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ImportMirrorScheduled {
    @Autowired
    private ImportMirrorService importMirrorService;
    @Autowired
    private UserGithubTokenService userGithubTokenService;


    /**
     * 定时任务，消费redis队列中待导入或代同步的仓库信息，请求云效进行导入或同步
     */
    @Scheduled(cron = "${importMirror.cron:*/2 * * * * ?}")
    public void exec() {
        importMirrorService.exec();
    }


    /**
     * 定时任务，验证用户token是否有效，并更新token状态，每日凌晨一点执行
     */
    //@Scheduled(cron = "${userToken.producer.cron:0 0 1 * * ?}")
    public void execVerifyTokenProducer() {
        userGithubTokenService.execVerifyTokenProducer();
    }


    /**
     * 定时任务，验证用户token是否有效，并更新token状态，
     */
    //@Scheduled(cron = "${userToken.consumer.cron:*/5 * * * * ?}")
    public void execVerifyTokenConsumer() {
        userGithubTokenService.execVerifyTokenConsumer();
    }
}
